package com.aqie.easy.math;

import java.util.ArrayList;
import java.util.List;

/**
 * 728. 自除数
 */
public class SelfDividingNumbers {
    public List<Integer> selfDividingNumbers(int left, int right) {
        List<Integer> res = new ArrayList<>();
        for (int i = left; i <= right;i++){
            if (isDivided(i)){
                res.add(i);
            }
        }
        return res;
    }

    public static void main(String[] args) {
        /**
         * 给定一个整数 拿到每位上的数字 123
         */
        int num = 123;
        System.out.println(isDivided(124));
        System.out.println(isDivided(127));
        System.out.println(isDivided(21));
        System.out.println(isDivided(22));
    }

    private static Boolean isDivided(int num) {
        // 原值不嫩在循环中变化
        int trueNum = num;
        while (num > 0){
            int tmp = num % 10;
//            System.out.println(tmp);
            // 被除数不能为0
            if (tmp == 0 || trueNum % tmp != 0){
                return false;
            }
            num /= 10;
        }
        return true;
    }
}
